#include<iostream>
#include<cstring>
using namespace std;
class Person
{
    protected:
        string name;
        int age;
    public:
        Person(string _na,int _age):name(_na),age(_age){ }
        void display()
        {
            cout<<name<<" "<<age<<" ";
        }
};
class FreeStu:public Person
{
    protected:
        int Score;
        char AllScore;
    public:
        FreeStu(string _na,int _age,int _Sc):Person(_na,_age)
        {
            Score=_Sc;
            if(Score>=85)
                AllScore='A';
            else if(Score>=75)
                AllScore='B';
            else if (Score>=65)
            {
                AllScore='C';
            }
            else if(Score>=60)
                AllScore='D';
            else
                AllScore='F';
        }
        void display()
        {
            Person::display();
            cout<<AllScore<<endl;
        }
};
class NotFree:public Person
{
    protected:
        int TestScore,NorScore;
        char AllScore;
    public:
        NotFree(string _na,int _age,int _Tsc,int _Nsc):Person(_na,_age)
        {
            TestScore=_Tsc;
            NorScore=_Nsc;
            double tmp=double(TestScore)*0.4+double(NorScore)*0.6;
            if(tmp>=85)
                AllScore='A';
            else if(tmp>=75)
                AllScore='B';
            else if (tmp>=65)
                AllScore='C';
            else if(tmp>=60)
                AllScore='D';
            else
                AllScore='F';
        }
        void display()
        {
            Person::display();
            cout<<AllScore<<endl;
        }
};
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        char tag;
        cin>>tag;
        string name;
        int age,test,norm;
        if(tag=='R')
        {
            cin>>name>>age>>test>>norm;
            NotFree tmp(name,age,test,norm);
            tmp.display();
        }
        else if(tag=='S')
        {
            cin>>name>>age>>test;
            FreeStu tmp2(name,age,test);
            tmp2.display();
        }
    }
}